package com.kfxie.controller;

import com.kfxie.domain.User;
import com.kfxie.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @RequestMapping("/findAll")
    public ModelAndView findAll(){
        ModelAndView md = new ModelAndView();
        md.addObject("users",userService.findAll());
        md.setViewName("index");
        return md;
    }
    @RequestMapping(value ="/save",produces = "text/html;charset=utf-8;")
    @ResponseBody
    public String save(User u, HttpSession session){
       userService.save(u);
        return "添加成功！";
    }

}
